import {Query} from "../../tools/query.ts";
import type {MetaView} from "./meta.types.ts";
import type {MorghulisChannel} from "./channel.types.ts";

export type DataItem = { [key: string]: any }
export type DataItemId = string | number
export type DaoTypes = 'orm' | 'mon'
export type DaoConfig = {
    auth?: boolean,
} & MorghulisChannel


export type Ticker = {
    length: number | string,
    index: number | string,
    percentage: number
} | null
export type DaoInfo = {
    current: number,
    total: number,
    page: number,
    size: number
}

export type DaoItemCallback = (item: DataItem) => void
export type DaoCallback = () => void
export type DaoViewCallback = (view: MetaView) => void
export type DaoPayload = { results: DataItem[], total?: number }
export type DaoResultsCallback = (payload: DaoPayload) => void

export type DaoStatus = {
    loading: boolean,
    payload?: Ticker
}

export type Dao = {
    save_one: (item: DataItem, callback: DaoItemCallback) => void,
    delete_one: (id: DataItemId, callback: DaoCallback) => void,
    find_one: (id: DataItemId, callback: DaoItemCallback) => void,
    save_many: (array: DataItem[]) => void,
    delete_many: (query: Query, callback: DaoCallback) => void,
    find_many: (query: Query, callback: DaoResultsCallback) => void,
    update_many: (query: Query, template: DataItem, callback: DaoCallback) => void,
    status: DaoStatus,
    meta: (callback: DaoViewCallback) => void
}


// export type DaoMetaProps = {
//     db: DaoDatabaseType,
//     entity: string,
//     code?: string,
//     auth?: boolean
// }
//
// export type DaoDataProps = {
//     includes?: DataItem,
//     excludes?: DataItem,
//     orders?: Orders,
// }
//
//
// export type DaoUiProps = UI & {
//     buttons?: MTableButton[]
// }
